Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
@storybook/preview-api
Advanced tools
The @storybook/preview-api package is part of the Storybook ecosystem, which is a tool for developing UI components in isolation for React, Vue, Angular, and more. This package provides APIs to interact with the Storybook preview, allowing developers to control the rendering of stories, listen to events, and manipulate the state of the Storybook UI.
Fetching and rendering stories
This feature allows developers to fetch story data by ID and render it using a custom component or utility.
import { useStorybookApi } from '@storybook/api';
function MyComponent() {
const api = useStorybookApi();
const story = api.getData('some-story-id');
return <StoryRenderer story={story} />;
}
Listening to Storybook events
This feature enables components to listen to Storybook-specific events and react accordingly, as well as emit events to the Storybook environment.
import { useEffect } from 'react';
import { useChannel } from '@storybook/api';
function MyComponent() {
const emit = useChannel({
'storybook/my-event': (eventData) => {
console.log('Event data:', eventData);
}
});
useEffect(() => {
emit('storybook/my-event', { payload: 'data' });
}, [emit]);
return <div>Check the console for event data.</div>;
}
Manipulating the Storybook UI
Developers can use this feature to programmatically control the Storybook UI, such as changing the current story displayed.
import { addons } from '@storybook/addons';
addons.setChannel(new Channel({ transport: new PostmsgTransport({ key: 'iframe-key' }) }));
addons.getChannel().emit('setCurrentStory', { storyId: 'some-story-id' });
This package allows developers to create callbacks that appear in the actions panel of the Storybook UI when clicked. It is similar to @storybook/preview-api in that it enhances the Storybook development experience but focuses on actions rather than preview functionality.
This package provides a way to create links between stories. It is similar to @storybook/preview-api in that it interacts with the Storybook UI, but it specifically focuses on linking stories together rather than providing a general API for preview manipulation.
This addon shows the source of the story next to the story itself. While it enhances the Storybook experience by providing source code context, it does not offer an API for controlling the preview like @storybook/preview-api does.
FAQs
Unknown package
The npm package @storybook/preview-api receives a total of 6,263,804 weekly downloads. As such, @storybook/preview-api popularity was classified as popular.
We found that @storybook/preview-api demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 11 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.